package com.atguigu.gmall.list.service.impl;

import com.atguigu.gmall.list.respository.GoodsEsRepostory;
import com.atguigu.gmall.list.service.SkuEsService;
import com.atguigu.gmall.model.list.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author 钟涛
 * @version 1.0
 * @description: TODO
 * @date 2021/12/18 11:53
 */
@Service
public class SkuEsServiceImpl implements SkuEsService {
    @Autowired
    private GoodsEsRepostory goodsEsRepostory;

    @Override
    public void upSku(Goods goods) {
        //上架
        goodsEsRepostory.save(goods);
    }

    @Override
    public void downSku(Long skuId) {
        //下架
        goodsEsRepostory.deleteById(skuId);
    }

    @Override
    public void incrementHotScore(Long skuId, Long hotScore) {
       //增加热度分
        Optional<Goods> byId = goodsEsRepostory.findById(skuId);
        if(byId.isPresent()){//数据是否存在
            //数据存在
            Goods goods = byId.get();
            goods.setHotScore(hotScore);
            goodsEsRepostory.save(goods);
        }
    }
}
